package cn.ld.module.system.dal.mapper.dept;

import cn.ld.framework.common.pojo.PageResult;
import cn.ld.framework.mybatis.core.mapper.BaseMapperX;
import cn.ld.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ld.module.system.controller.admin.dept.vo.post.PostPageInVO;
import cn.ld.module.system.dal.entity.dept.PostEntity;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.List;

@Mapper
public interface PostMapper extends BaseMapperX<PostEntity> {

    default List<PostEntity> selectList(Collection<Long> ids, Collection<Integer> statuses) {
        return selectList(new LambdaQueryWrapperX<PostEntity>()
                .inIfPresent(PostEntity::getId, ids)
                .inIfPresent(PostEntity::getStatus, statuses));
    }

    default PageResult<PostEntity> selectPage(PostPageInVO inVO) {
        return selectPage(inVO, new LambdaQueryWrapperX<PostEntity>()
                .likeIfPresent(PostEntity::getCode, inVO.getCode())
                .likeIfPresent(PostEntity::getName, inVO.getName())
                .eqIfPresent(PostEntity::getStatus, inVO.getStatus())
                .orderByDesc(PostEntity::getId));
    }

    default PostEntity selectByName(String name) {
        return selectOne(PostEntity::getName, name);
    }

    default PostEntity selectByCode(String code) {
        return selectOne(PostEntity::getCode, code);
    }

}
